package com.jayson.myblog.controller;

import com.jayson.myblog.pojo.BlogArticle;
import com.jayson.myblog.service.BlogArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/article")
public class ArticleController {

    @Autowired
    private BlogArticleService blogArticleService;

    @RequestMapping("/list")
    public String list(Integer pageNo, Integer pageSize, Model model){
        pageNo = null == pageNo ? 0 : pageNo;
        pageSize = null == pageSize ? 2 : pageSize;
        Pageable pageable = PageRequest.of(pageNo, pageSize);
        Page<BlogArticle> page = blogArticleService.findPage(pageable);
        model.addAttribute("page", page);

        return "client/index";
    }
}
